<?php

namespace app\admin\controller\shopro\goods;

use app\common\controller\Backend;
use think\Db;

/**
 * 商品修改申请
 *
 * @icon fa fa-circle-o
 */
class Xg extends Backend
{

    /**
     * Xg模型对象
     * @var \app\admin\model\shopro\goods\Xg
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\shopro\goods\Xg;

    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);
            foreach ($list->items() as $v){

                $v['goods_name'] = Db::name('shopro_goods')->where('id',$v['goods_id'])->value('title');
                $v['store_name'] = Db::name('shopro_store')->where('id',$v['store_id'])->value('name');
                $v['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('nickname');
            }
            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }
    public function collection_status($type,$ids){
        $info = Db::name('shopro_goods_xg')->where('id',$ids)->find();
        if (empty($info)){$this->error('信息不存在');}
        if ($type==1){
            if ($info['status']==1){$this->error('当前已确认修改，请核查');}
            Db::name('shopro_goods_xg')->where('id', $ids)->update(['status' => 1,'updatetime'=>time()]);
            $this->success("已确认修改");
        }
        if ($type==0){
            if ($info['status']==0){$this->error('当前已为未修改，请核查');}
            Db::name('shopro_goods_xg')->where('id', $ids)->update(['status' => 0]);
            $this->success("设置未修改成功");
        }
        $this->error('修改错误');

    }

    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */


}
